package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdviceAsk;
import com.ruoyi.system.service.IAdviceAskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 意见建议Controller
 *
 * @author ruoyi
 * @date 2025-09-04
 */
@RestController
@RequestMapping("/system/advice")
public class AdviceAskController extends BaseController
{
    @Autowired
    private IAdviceAskService adviceAskService;

    /**
     * 查询意见建议列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(AdviceAsk adviceAsk)
    {
        startPage();
        List<AdviceAsk> list = adviceAskService.selectAdviceAskList(adviceAsk);
        return getDataTable(list);
    }

    /**
     * 导出意见建议列表
     */
//    @PreAuthorize("@ss.hasPermi('system:ask:export')")
//    @Log(title = "意见建议", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, AdviceAsk adviceAsk)
//    {
//        List<AdviceAsk> list = adviceAskService.selectAdviceAskList(adviceAsk);
//        ExcelUtil<AdviceAsk> util = new ExcelUtil<AdviceAsk>(AdviceAsk.class);
//        util.exportExcel(response, list, "意见建议数据");
//    }

    /**
     * 获取意见建议详细信息
     */
    @GetMapping(value = "/{adviceId}")
    public AjaxResult getInfo(@PathVariable("adviceId") String adviceId)
    {
        return success(adviceAskService.selectAdviceAskByAdviceId(adviceId));
    }

    /**
     * 新增意见建议
     */
    @Anonymous
    @PostMapping
    public AjaxResult add(@ModelAttribute AdviceAsk adviceAsk)
    {
        return toAjax(adviceAskService.insertAdviceAsk(adviceAsk));
    }

    /**
     * 修改意见建议
     */

    @Log(title = "意见建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ModelAttribute AdviceAsk adviceAsk)
    {
        return toAjax(adviceAskService.updateAdviceAsk(adviceAsk));
    }

    /**
     * 删除意见建议
     */
    @Log(title = "意见建议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adviceIds}")
    public AjaxResult remove(@PathVariable String[] adviceIds)
    {
        return toAjax(adviceAskService.deleteAdviceAskByAdviceIds(adviceIds));
    }
}
